package com.sr.main;


import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import com.sr.config.DataBaseConfig;
import com.sr.config.RedisConfig;
import com.sr.pojo.Role;
import com.sr.service.RedisTemplateService;
import com.sr.service.RoleService;

public class SrMain {

    public static void main(String[] args) {
        redistemplateservice();
    }

    public static void testCache1() {
        // 使用注解Spring IoC容器
        ApplicationContext ctx = new AnnotationConfigApplicationContext(DataBaseConfig.class, RedisConfig.class);
        // 获取角色服务类
        RoleService roleService = ctx.getBean(RoleService.class);
        Role role = new Role();
        role.setRoleName("role_name_1");
        role.setNote("role_note_1");
        // 插入角色
        roleService.insertRole(role);
        // 获取角色
        Role getRole = roleService.getRole(role.getId());
        getRole.setNote("role_note_1_update");
        // 更新角色
        roleService.updateRole(getRole);
        System.out.println("id = " + getRole.getId());
    }

    public static void redistemplateservice() {
        // 使用注解Spring IoC容器
        ApplicationContext ctx = new AnnotationConfigApplicationContext(DataBaseConfig.class, RedisConfig.class);
        RedisTemplateService redisTemplateService = ctx.getBean(RedisTemplateService.class);
        redisTemplateService.execMultiCommand();
        redisTemplateService.execPipeline();
        redisTemplateService.execPipeline();
    }

}